package service.impl;

import dao.ShopCarDao;
import dao.impl.ShopCarDaoImpl;
import model.ShopCar;
import service.ShopCarService;

import java.util.List;

public class ShopCarServiceImpl  implements ShopCarService {
    ShopCarDao shopCarDao = new ShopCarDaoImpl();
    @Override
    public boolean addInfo(ShopCar shopCar) {
        ShopCar shopCar1 = findByUG(shopCar.getUserId(),shopCar.getGoodsId());
        if(shopCar1!=null){
            shopCar1.setCount(shopCar1.getCount()+1);
            boolean flag = updateInfo(shopCar1);
            return flag;
        }
        return shopCarDao.addInfo(shopCar);
    }

    @Override
    public boolean delInfoById(Integer id) {
        return shopCarDao.delByPK(id);
    }

    @Override
    public List<ShopCar> findByUserId(Integer userId) {
        return shopCarDao.findInfoByUserID(userId);
    }

    @Override
    public boolean updateInfo(ShopCar shopCar) {
        return shopCarDao.update(shopCar);
    }

    @Override
    public ShopCar findByUG(Integer userId, Integer goodsId) {
        return shopCarDao.findByUG(userId,goodsId);
    }

    @Override
    public ShopCar findByPK(Integer id) {
        return shopCarDao.findByPK(id);
    }
}
